from PyQt5 import QtWidgets
from PyQt5 import QtGui
import sys
import t_close_main_windowrcc_rc


class QPushButtonTest(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(QPushButtonTest, self).__init__(parent)

        self.setWindowTitle("QPushButton 测试")

        self.button1 = QtWidgets.QPushButton("Button1")
        self.button1.setCheckable(True)
        self.button1.toggle()
        self.button1.clicked.connect(lambda: self.witch_button(self.button1))
        self.button1.clicked.connect(self.button_state)

        self.btn2 = QtWidgets.QPushButton("Image")
        self.btn2.setIcon(QtGui.QIcon(QtGui.QPixmap(":/pic/python.jpg")))
        self.btn2.clicked.connect(lambda: self.witch_button(self.btn2))

        self.btn3 = QtWidgets.QPushButton("Disabled")
        self.btn3.setEnabled(False)

        self.btn4 = QtWidgets.QPushButton("&Download")
        self.btn4.clicked.connect(lambda: self.witch_button(self.btn4))

        vlayout = QtWidgets.QVBoxLayout()
        vlayout.addWidget(self.button1)
        vlayout.addWidget(self.btn2)
        vlayout.addWidget(self.btn3)
        vlayout.addWidget(self.btn4)
        self.setLayout(vlayout)

    def button_state(self):
        info = "button pressed" if self.button1.isChecked() else "button released"
        print(info)

    def witch_button(self, button):
        print("button clicked : ", button.text())


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)

    win = QPushButtonTest()
    win.show()

    sys.exit(app.exec_())
